package com.tkxs.global.globalException;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import com.tkxs.global.exception.MyException;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@ControllerAdvice
@ResponseBody
public class GlobalExceptionHandler {
	
	
	/**
	 * 
	 * @return
	 * 
	 *  默认处理所有的异常
	 */
	@ExceptionHandler(Exception.class)
	public String defaultExceptionHandler(Exception e) {
		log.error(e.toString());
		return "服务器内部异常";
	}
	
	/**
	 * 
	 * @param e
	 * @return
	 * 只会处理注解中明确显示的异常
	 */
	@ExceptionHandler(MyException.class)
	public String myExceptionHandler(Exception e) {
		log.error(e.toString());
		return "自定义异常";
	}

	
}
